package com.ews.onlineexchange.service;

import java.util.List;

import javax.enterprise.inject.Model;
import javax.inject.Inject;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang3.StringUtils;

import com.ews.onlineexchange.model.approved.ApprovedClass;
import com.ews.onlineexchange.model.approved.ApprovedType;

@Model
public class ApprovedClassList extends EntityQuery<ApprovedClass> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String approvedType;

	public ApprovedClassList() {
		setMaxResults(null);
	}

	@Override
	protected List<Predicate> getRestrictions(CriteriaBuilder cb, Root<ApprovedClass> entity) {
		List<Predicate> restrictions = super.getRestrictions(cb, entity);
		
		if (!StringUtils.isBlank(getApprovedType())) {
			ApprovedType approvedType = ApprovedType.valueOf(getApprovedType());
			restrictions.add(cb.equal(entity.get("approvedType"), approvedType));
		}
		
		return restrictions;
	}

	public String getApprovedType() {
		return approvedType;
	}

	public void setApprovedType(String approvedType) {
		this.approvedType = approvedType;
	}

}
